<template>
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogTableVisible">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="岗位名称" prop="postName">
        <el-input v-model="ruleForm.postName" />
      </el-form-item>
      <el-form-item label="岗位编号" prop="postCode">
        <el-input v-model="ruleForm.postCode" />
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input v-model="ruleForm.sort" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-radio-group v-model="ruleForm.status">
          <el-radio label="0">正常</el-radio>
          <el-radio label="1">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="ruleForm.remark" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">{{ btnStr }}</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { getToken } from '@/utils/auth'
import { savePost } from '@/api/home_'

export default {
  filters: {

  },
  components: {

  },
  data() {
    return {
      httpUrl: process.env.VUE_APP_BASE_API,
      headers: {
        Authorization: 'bearer ' + getToken()
      },
      btnStr: '立即创建',
      title: '新增',
      dialogTableVisible: false,
      ruleForm: {
        "createTime": "",
        "id": 0,
        "postCode": "",
        "postName": "",
        "remark": "",
        "sort": 0,
        "status":'0',
        "updateTime": ""
      },
      rules: {
        account: [
          { required: true, message: '请输入用户账号', trigger: 'blur' }
        ]
      }
    }
  },
  created() {

  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          savePost(this.ruleForm).then(res => {
            if(res.code==200){
              this.$message.success(res.msg)
              this.dialogTableVisible = false
              this.resetForm()
              this.$emit('refresh')
            }else{
              this.$message.error(res.msg)
            }
          })
        } else {
          return false
        }
      })
    },
    resetForm(formName) {
      this.ruleForm = {
        "createTime": "",
        "id": 0,
        "postCode": "",
        "postName": "",
        "remark": "",
        "sort": 0,
        "status": '0',
        "updateTime": ""
      }
      // this.$refs[formName].resetFields();
    },
    setVal(v) {
      this.title = v == 'add' ? '新增' : '修改'
      this.btnStr = v == 'add' ? '立即创建' : '修改'
      if (v != 'add') {
        this.ruleForm = JSON.parse(v)
        this.ruleForm.status = this.ruleForm.status + ''
      } else {
        this.resetForm()
      }
      this.dialogTableVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
>>>.el-upload-list{
    position:absolute !important;
    left:100px !important;
    top:-6px !important;
}
.el-form{
    display:flex;
    flex-direction:row;
    flex-wrap:wrap;
    .el-form-item{
        width:50%;
    }
}
</style>
